package com.wzy.test;


import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Scanner;

public class Demo01 {
    public static void main(String[] args) {
        int i = 1;
        LocalDate theBirthday = null;
        while (i == 1) {
            Scanner scanner = new Scanner(System.in);
            System.out.println("请输入你的生日:");
            String birthday = scanner.next();
            DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");

            try {
                theBirthday = LocalDate.parse(birthday, dateTimeFormatter);
                //System.out.println(theBirthday);
                i = 2;
            } catch (Exception e) {
                System.err.println("格式输入错误,格式为yyyy-MM-dd");
                i = 1;
            }
        }
        System.out.println("格式正确计算中....");
        LocalDate now = LocalDate.now();

        LocalDate currentBirthday = LocalDate.of(now.getYear(), theBirthday.getMonthValue(), theBirthday.getDayOfMonth());

        if (currentBirthday.isAfter(now)) {
            long l1 = currentBirthday.toEpochDay();
            long l2 = now.toEpochDay();
            System.out.println("距离下一个生日:" + (l1 - l2) + "天");
        } else {
            long l1 = now.toEpochDay();
            LocalDate nextBirthday = LocalDate.of(currentBirthday.getYear() + 1, theBirthday.getMonthValue(), theBirthday.getDayOfMonth());
            long l2 = nextBirthday.toEpochDay();
            System.out.println("距离下一个生日:" + (l2 - l1) + "天");
        }
    }
}
